package com.suning.sawp.web.controller;

import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suning.sawp.constants.ClerkConstants;
import com.suning.sawp.constants.ConfigConstants;
import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.bi.BiStoreCateSaleDetailDto;
import com.suning.sawp.dto.bi.BiStoreJxcCateInfo;
import com.suning.sawp.dto.bi.BiStoreJxcInfo;
import com.suning.sawp.dto.bi.BiStoreSaleCompletaRateRankingDto;
import com.suning.sawp.dto.bi.BiStoreSaleCompleteRateDto;
import com.suning.sawp.dto.bi.BiStoreSaleDetailDto;
import com.suning.sawp.dto.bi.BiStoreSaleDto;
import com.suning.sawp.dto.bi.BiStoreYbCateInfo;
import com.suning.sawp.dto.bi.BiStoreYbDetailDto;
import com.suning.sawp.dto.bi.CmmdtyAvgPriceDto;
import com.suning.sawp.dto.bi.CmmdtySaleDetailsDto;
import com.suning.sawp.dto.bi.TopCateDto;
import com.suning.sawp.dto.bi.sale.IndexCockpitDto;
import com.suning.sawp.dto.bi.sale.StoreGuideIndexDay;
import com.suning.sawp.dto.bi.sale.StoreGuideIndexMonth;
import com.suning.sawp.dto.bi.sale.StoreGuideSaleCompleteRate;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.mainpush.StoreManDto;
import com.suning.sawp.intf.bi.BiBrandService;
import com.suning.sawp.intf.bi.BiStoreDateService;
import com.suning.sawp.intf.bi.StoreGuideBiService;
import com.suning.sawp.intf.storeman.StoreManService;
import com.suning.sawp.po.bi.BiBrandSaleInfoDto;
import com.suning.sawp.service.util.SCMConfigUtil;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 
 * 门店BI数据接口控制类<br>
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/bi")
public class StoreBiDataController extends DjBaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(StoreBiDataController.class);

    @Resource
    BiBrandService biBrandService;

    @Resource
    StoreManService storeManService;

    /**
     * 店长统计服务
     */
    @Autowired
    BiStoreDateService biStoreDateService;

    @Resource
    StoreGuideBiService storeGuideBiService;

    /**
     * 
     * 功能描述: 督导首页（日维度）接口<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getStoreGuideIndexDay.do")
    public MyGsonView getStoreGuideIndexDay(Principal principal, String cateCode) {
        ReturnMsg<StoreGuideIndexDay> retMsg = storeGuideBiService.getStoreGuideIndexDay(principal.getName(), cateCode);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 督导首页（月维度）接口<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getStoreGuideIndexMonth.do")
    public MyGsonView getStoreGuideIndexMonth(Principal principal, String cateCode) {
        ReturnMsg<StoreGuideIndexMonth> retMsg = storeGuideBiService.getStoreGuideIndexMonth(principal.getName(),
                cateCode);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 督导首页（月维度）接口<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/cateSaleCompleteRates.do")
    public MyGsonView cateSaleCompleteRates(Principal principal, String year, String cateCode) {
        ReturnMsg<StoreGuideSaleCompleteRate> retMsg = storeGuideBiService.getStoreCateSaleCompleteRates(
                principal.getName(), year, cateCode);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getCockpitIndex.do")
    public MyGsonView getCockpitIndex(Principal principal, String cateCode) {
        ReturnMsg<IndexCockpitDto> retMsg = storeGuideBiService.getCockpitIndex(principal.getName(), cateCode);
        return setGsonView(retMsg);
    }

    /**
     * 品牌日维度销售额排行
     *
     * @param cateCode
     * @param queryTime
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryBrandSaleByDay.do")
    @ResponseBody
    public ReturnMsg<BiBrandSaleInfoDto> queryBrandSaleAmountDay(String cateCode, String queryTime,
            String orderCondition, Principal principal) {

        ReturnMsg<BiBrandSaleInfoDto> returnMsg = new ReturnMsg<BiBrandSaleInfoDto>();
        Object[] args = { principal.getName(), cateCode, queryTime };
        LOGGER.info("queryBrandSaleAmountDay cateCode:{}, queryTime:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("queryBrandSaleAmountDay storeManDto is null for " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0027);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0027));
            return returnMsg;
        }

        // 校验请求入参
        if (StringUtils.isBlank(queryTime) || StringUtils.isBlank(orderCondition)) {
            LOGGER.error("queryBrandSaleAmountDay  input error for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0001);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0001));
            return returnMsg;
        }

        ReturnMsg<BiBrandSaleInfoDto> result = biBrandService.queryBrandSaleByDay(cateCode, queryTime, orderCondition,
                storeManDto);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.info("queryBrandSaleAmountDay result :", result.getData());
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("queryBrandSaleAmountDay  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));

        }
        return returnMsg;
    }

    /**
     * 品牌月维度销售额排行
     *
     * @param cateCode
     * @param queryTime
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryBrandSaleByMonth.do")
    @ResponseBody
    public ReturnMsg<BiBrandSaleInfoDto> queryBrandSaleByMonth(String cateCode, String queryTime,
            String orderCondition, Principal principal) {

        ReturnMsg<BiBrandSaleInfoDto> returnMsg = new ReturnMsg<BiBrandSaleInfoDto>();
        Object[] args = { principal.getName(), cateCode, queryTime };
        LOGGER.info("queryBrandSaleAmountDay cateCode:{}, queryTime:{}", args);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        // 校验店员信息
        if (storeManDto == null) {
            LOGGER.error("queryBrandSaleAmountDay storeManDto is null for " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0027);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0027));
            return returnMsg;
        }

        // 校验请求入参
        if (StringUtils.isBlank(queryTime) || StringUtils.isBlank(orderCondition)) {
            LOGGER.error("queryBrandSaleAmountDay  input error for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0001);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0001));
            return returnMsg;
        }

        ReturnMsg<BiBrandSaleInfoDto> result = biBrandService.queryBrandSaleByMonth(cateCode, queryTime,
                orderCondition, storeManDto);

        if (result != null && ReturnMsg.SUCCESS.equals(result.getRetFlag())) {
            LOGGER.info("queryBrandSaleAmountDay result :", result.getData());
            returnMsg.setData(result.getData());
        } else {
            LOGGER.error("queryBrandSaleAmountDay  input result fail  for staffid  " + principal.getName());
            returnMsg.setErrorCode(ErrorCodeConstants.ERR_0028);
            returnMsg.setRetFlag(ReturnMsg.FAIL);
            returnMsg.setErrorMessage(ErrorCodeConstants.ERR_MAP.get(ErrorCodeConstants.ERR_0028));

        }
        return returnMsg;
    }

    /**
     * 查询店长日销售数据 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryKeeperDataByDay.do")
    public MyGsonView queryKeeperDataByDay(Principal principal) {
        ReturnMsg<BiStoreSaleDto> returnMsg = new ReturnMsg<BiStoreSaleDto>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            // 店长权限
            if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                    || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                BiStoreSaleDto resp = biStoreDateService.queryKeeperDataByDay(storeManDto.getStaffId(),
                        storeManDto.getStoreCode());
                returnMsg.setData(resp);
            } else {
                returnMsg.setError(ErrorCodeConstants.ERR_0035);
                LOGGER.error("queryKeeperDataByDay not keeper,staffId=" + storeManDto);
            }
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryKeeperDataByDay error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询店长月销售数据 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryKeeperDataByMonth.do")
    public MyGsonView queryKeeperDataByMonth(Principal principal) {
        ReturnMsg<BiStoreSaleDto> returnMsg = new ReturnMsg<BiStoreSaleDto>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            // 店长权限
            if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                    || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                BiStoreSaleDto resp = biStoreDateService.queryKeeperDataByMonth(storeManDto.getStoreCode());
                returnMsg.setData(resp);
            } else {
                returnMsg.setError(ErrorCodeConstants.ERR_0035);
                LOGGER.error("queryKeeperDataByMonth not keeper,staffId=" + storeManDto);
            }
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryKeeperDataByMonth error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店日销售详情 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreSaleDetailByDay.do")
    public MyGsonView queryStoreSaleDetailByDay(Principal principal, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryStoreSaleDetailByDay month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreSaleDetailDto> list = biStoreDateService.queryStoreSaleDetailByDay(
                            storeManDto.getStoreCode(), month);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreSaleDetailByDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreSaleDetailByDay error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店月销售详情 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param year
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreSaleDetailByMonth.do")
    public MyGsonView queryStoreSaleDetailByMonth(Principal principal, String year) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断年份是否为空
        if (StringUtils.isBlank(year)) {
            LOGGER.warn("queryStoreSaleDetailByMonth year is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreSaleDetailDto> list = biStoreDateService.queryStoreSaleDetailByMonth(
                            storeManDto.getStoreCode(), year);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreSaleDetailByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreSaleDetailByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店品类日维度销售排行 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param day
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCateSaleAmountDay.do")
    public MyGsonView queryStoreCateSaleAmountDay(Principal principal, String day) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断天是否为空
        if (StringUtils.isBlank(day)) {
            LOGGER.warn("queryStoreCateSaleAmountDay day is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreCateSaleDetailDto> list = biStoreDateService.queryStoreCateSaleAmountDay(
                            storeManDto.getStoreCode(), day);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCateSaleAmountDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCateSaleAmountDay error,staffId=" + principal.getName(), e);
            }
        }

        return setGsonView(returnMsg);
    }

    /**
     * 查询门店品类日维度销量排行 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param day
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCateSaleVolumeDay.do")
    public MyGsonView queryStoreCateSaleVolumeDay(Principal principal, String day) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断天是否为空
        if (StringUtils.isBlank(day)) {
            LOGGER.warn("queryStoreCateSaleVolumeDay day is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreCateSaleDetailDto> list = biStoreDateService.queryStoreCateSaleVolumeDay(
                            storeManDto.getStoreCode(), day);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCateSaleVolumeDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCateSaleVolumeDay error,staffId=" + principal.getName(), e);
            }
        }

        return setGsonView(returnMsg);
    }

    /**
     * 查询门店品类月销售额排行 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCateSaleAmountMonth.do")
    public MyGsonView queryStoreCateSaleAmountMonth(Principal principal, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryStoreCateSaleAmountMonth month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreCateSaleDetailDto> list = biStoreDateService.queryStoreCateSaleAmountMonth(
                            storeManDto.getStoreCode(), month);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCateSaleAmountMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCateSaleAmountMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店品类月销量排行 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCateSaleVolumeMonth.do")
    public MyGsonView queryStoreCateSaleVolumeMonth(Principal principal, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryStoreCateSaleVolumeMonth month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    List<BiStoreCateSaleDetailDto> list = biStoreDateService.queryStoreCateSaleVolumeMonth(
                            storeManDto.getStoreCode(), month);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCateSaleVolumeMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCateSaleVolumeMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询督导品类日销售详情 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCateSaleDetailByDay.do")
    public MyGsonView queryCateSaleDetailByDay(Principal principal, String cateCode, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month) || StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryCateSaleDetailByDay month or cateCode is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 督导权限
                if (ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    List<BiStoreSaleDetailDto> list = biStoreDateService.queryCateSaleDetailByDay(
                            storeManDto.getStoreCode(), cateCode, month);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    // 查询品类数据
                    result.put("cateList", biStoreDateService.getCategory(storeManDto.getCategories(), cateCode));
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateSaleDetailByDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateSaleDetailByDay error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询督导品类月销售详情 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @param year
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCateSaleDetailByMonth.do")
    public MyGsonView queryCateSaleDetailByMonth(Principal principal, String cateCode, String year) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断年份是否为空
        if (StringUtils.isBlank(year) || StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryCateSaleDetailByMonth year or cateCode is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 督导权限
                if (ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    List<BiStoreSaleDetailDto> list = biStoreDateService.queryCateSaleDetailByMonth(
                            storeManDto.getStoreCode(), cateCode, year);
                    Map<String, Object> result = new HashMap<String, Object>();
                    result.put("list", list);
                    // 查询品类数据
                    result.put("cateList", biStoreDateService.getCategory(storeManDto.getCategories(), cateCode));
                    returnMsg.setData(result);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateSaleDetailByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateSaleDetailByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店，品类月份完成率 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCompleteRate.do")
    public MyGsonView queryStoreCompleteRate(Principal principal, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryStoreCompleteRate month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    BiStoreSaleCompleteRateDto resp = biStoreDateService.queryStoreCompleteRate(month,
                            storeManDto.getStoreCode(), storeManDto.getStoreName());
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCompleteRate not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCompleteRate error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 查询门店同大区销售完成率排行 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCompleteRateRanking.do")
    public MyGsonView queryStoreCompleteRateRanking(Principal principal, String month) {
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断月份是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryStoreCompleteRateRanking month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    BiStoreSaleCompletaRateRankingDto resp = biStoreDateService.queryStoreCompleteRateRanking(month,
                            storeManDto.getSaleRegionCode(), storeManDto.getStoreCode(), storeManDto.getStoreName());
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryStoreCompleteRateRanking not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryStoreCompleteRateRanking error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }

    /**
     * 
     * 功能描述: 日维度店长查询门店以及品类平均客单价<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param date 
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCustAvgPriceByDay.do")
    public MyGsonView queryCustAvgPriceByDay(Principal principal, String date) {
        LOGGER.info("queryCustAvgPriceByDay. date: " + date);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断日期是否为空
        if (StringUtils.isBlank(date)) {
            LOGGER.warn("queryCustAvgPriceByDay date is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    returnMsg.setData(biStoreDateService.queryCustAvgPriceByDay(storeManDto, date));
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCustAvgPriceByDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCustAvgPriceByDay error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 月维度店长查询门店以及品类平均客单价<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param date 
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCustAvgPriceByMonth.do")
    public MyGsonView queryCustAvgPriceByMonth(Principal principal, String month) {
        LOGGER.info("queryCustAvgPriceByMonth. month: " + month);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断日期是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryCustAvgPriceByMonth month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    returnMsg.setData(biStoreDateService.queryCustAvgPriceByMonth(storeManDto, month));
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCustAvgPriceByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCustAvgPriceByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 日维度查询门店品牌平均单价(店长和督导权限)<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryBrandCommAvgPriceByDay.do")
    public MyGsonView queryBrandCommAvgPriceByDay(Principal principal, String cateCode, String date) {
        LOGGER.info("queryBrandCommAvgPriceByDay. cateCode: " + cateCode + ", date: " + date);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断类别、日期是否为空
        if (StringUtils.isBlank(date)) {
            LOGGER.warn("queryBrandCommAvgPriceByDay date is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else if (StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryBrandCommAvgPriceByDay cateCode is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长和督导权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    // 判断品类编码归属于此工号,不属于报参数异常
                    if (CollectionUtils.isEmpty(storeManDto.getCategories()) || !storeManDto.validHasCate(cateCode)) {
                        LOGGER.error("queryBrandCommAvgPriceByDay. cateCode:{} is not  belong to this man", cateCode);
                        returnMsg.setError(ErrorCodeConstants.ERR_0001);
                    } else {
                        returnMsg.setData(storeGuideBiService.queryBrandCommAvgPriceByDay(storeManDto, cateCode, date));
                    }
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryBrandCommAvgPriceByDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryBrandCommAvgPriceByDay error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    
    }
    
    /**
     * 
     * 功能描述: 月维度查询门店品牌平均单价(店长督导权限)<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryBrandCommAvgPriceByMonth.do")
    public MyGsonView queryBrandCommAvgPriceByMonth(Principal principal, String cateCode, String month) {
        LOGGER.info("queryBrandCommAvgPriceByMonth. cateCode: " + cateCode + ", month: " + month);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断类别、日期是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryBrandCommAvgPriceByMonth month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else if (StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryBrandCommAvgPriceByMonth cateCode is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长和督导权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId()) 
                        || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    // 判断品类编码归属于此工号,不属于报参数异常
                    if (CollectionUtils.isEmpty(storeManDto.getCategories()) || !storeManDto.validHasCate(cateCode)) {
                        LOGGER.error("queryBrandCommAvgPriceByMonth. cateCode:{} is not  belong to this man", cateCode);
                        returnMsg.setError(ErrorCodeConstants.ERR_0001);
                    } else {
                        returnMsg.setData(storeGuideBiService.queryBrandCommAvgPriceByMonth(storeManDto, cateCode, month));
                    }
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryBrandCommAvgPriceByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryBrandCommAvgPriceByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 日维度查询门店品类平均单价<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCateCommAvgPriceByDay.do")
    public MyGsonView queryCateCommAvgPriceByDay(Principal principal, String date) {
        LOGGER.info("queryCateCommAvgPriceByDay. date: " + date);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断日期是否为空
        if (StringUtils.isBlank(date)) {
            LOGGER.warn("queryCateCommAvgPriceByDay date is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    returnMsg.setData(biStoreDateService.queryCateCommAvgPriceByDay(storeManDto, date));
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateCommAvgPriceByDay not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateCommAvgPriceByDay error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 月维度查询门店品类平均单价<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCateCommAvgPriceByMonth.do")
    public MyGsonView queryCateCommAvgPriceByMonth(Principal principal, String month) {
        LOGGER.info("queryCateCommAvgPriceByMonth. month: " + month);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断日期是否为空
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryCateCommAvgPriceByMonth date is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    returnMsg.setData(biStoreDateService.queryCateCommAvgPriceByMonth(storeManDto, month));
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateCommAvgPriceByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateCommAvgPriceByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }


 /**
     * 
     *日维度查询门店品类延保销售列表
     * @param principal
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryYbCateByDay.do")
    public MyGsonView queryYbCateByDay(Principal principal,String date) {
        ReturnMsg<BiStoreYbDetailDto> returnMsg = new ReturnMsg<BiStoreYbDetailDto>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            
            if (StringUtils.isBlank(date)) {
                LOGGER.warn("queryYbCateByDay date is null");
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                return setGsonView(returnMsg);
            }
            
            // 店长权限
            if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                    || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                BiStoreYbDetailDto resp = biStoreDateService.queryYbCateByDay(storeManDto.getStoreCode(),date);
                returnMsg.setData(resp);
            } else {
                returnMsg.setError(ErrorCodeConstants.ERR_0035);
                LOGGER.error("queryYbCateByDay not keeper,staffId=" + storeManDto);
            }
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryYbCateByDay error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     *月维度查询门店品类延保销售列表
     * @param principal
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryYbCateByMonth.do")
    public MyGsonView queryYbCateByMonth(Principal principal,String month) {
        ReturnMsg<BiStoreYbDetailDto> returnMsg = new ReturnMsg<BiStoreYbDetailDto>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            if (StringUtils.isBlank(month)) {
                LOGGER.warn("queryYbCateByMonth month is null");
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                return setGsonView(returnMsg);
            }
            
            // 店长权限
            if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                    || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                BiStoreYbDetailDto resp = biStoreDateService.queryYbCateByMonth(storeManDto.getStoreCode(),month);
                returnMsg.setData(resp);
            } else {
                returnMsg.setError(ErrorCodeConstants.ERR_0035);
                LOGGER.error("queryYbCateByMonth not keeper,staffId=" + storeManDto);
            }
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryYbCateByMonth error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     *
     * @param principal
     * @param date
     * @param cateCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryYbStaffByDay.do")
    public MyGsonView queryYbStaffByDay(Principal principal,String date,String cateCode) {
        ReturnMsg<BiStoreYbCateInfo> returnMsg = new ReturnMsg<BiStoreYbCateInfo>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            if(StringUtils.isBlank(cateCode) || StringUtils.isBlank(date) ){
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                LOGGER.error("queryYbStaffByDay inputparm is blank,staffId=" + storeManDto);
                return setGsonView(returnMsg);
            }
            //如果不是八大品类
            if(StringUtils.isBlank(ConfigConstants.DEFAULT_CATE_MAP.get(cateCode))){
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                LOGGER.error("queryYbStaffByDay cateCode is error,cateCode=" + cateCode);
                return setGsonView(returnMsg);
            }
            BiStoreYbCateInfo resp = biStoreDateService.queryYbStaffByDay(storeManDto,date,cateCode);
            returnMsg.setData(resp);
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryYbStaffByDay error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }
    
    @RequestMapping("/queryYbStaffByMonth.do")
    public MyGsonView queryYbStaffByMonth(Principal principal,String month,String cateCode) {
        ReturnMsg<BiStoreYbCateInfo> returnMsg = new ReturnMsg<BiStoreYbCateInfo>();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            if(StringUtils.isBlank(cateCode) || StringUtils.isBlank(month) ){
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                LOGGER.error("queryYbStaffByMonth inputparm is blank,staffId=" + storeManDto);
                return setGsonView(returnMsg);
            }
            //如果不是八大品类
            if(StringUtils.isBlank(ConfigConstants.DEFAULT_CATE_MAP.get(cateCode))){
                returnMsg.setError(ErrorCodeConstants.ERR_0001);
                LOGGER.error("queryYbStaffByMonth cateCode is error,cateCode=" + cateCode);
                return setGsonView(returnMsg);
            }
            BiStoreYbCateInfo resp = biStoreDateService.queryYbStaffByMonth(storeManDto,month,cateCode);
            returnMsg.setData(resp);
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryYbStaffByMonth error,staffId=" + principal.getName(), e);
        }
        return setGsonView(returnMsg);
    }
    
    
    
    @RequestMapping("/queryCateJxcByDate.do")
    public MyGsonView queryCateJxcByDate(Principal principal,String date) {
        ReturnMsg<BiStoreJxcInfo> returnMsg = new ReturnMsg<BiStoreJxcInfo>();
        // 判断年份是否为空
        if (StringUtils.isBlank(date)) {
            LOGGER.warn("queryCateJxcByDate date is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                //  店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    BiStoreJxcInfo resp = biStoreDateService
                            .queryCateJxcByDate(storeManDto.getStoreCode(),date);
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateJxcByDate not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateJxcByDate error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    @RequestMapping("/queryCateJxcByMonth.do")
    public MyGsonView queryCateJxcByMonth(Principal principal,String month) {
        ReturnMsg<BiStoreJxcInfo> returnMsg = new ReturnMsg<BiStoreJxcInfo>();
        if (StringUtils.isBlank(month)) {
            LOGGER.warn("queryCateJxcByMonth month is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                // 店长权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId())) {
                    BiStoreJxcInfo resp = biStoreDateService
                            .queryCateJxcByMonth(storeManDto.getStoreCode(),month);
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryCateJxcByMonth not keeper,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCateJxcByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    @RequestMapping("/queryBrandJxcByDate.do")
    public MyGsonView queryBrandJxcByDate(Principal principal,String date,String cateCode) {
        ReturnMsg<BiStoreJxcCateInfo> returnMsg = new ReturnMsg<BiStoreJxcCateInfo>();
        if (StringUtils.isBlank(date) || StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryBrandJxcByDate input is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                //如果不是八大品类
                if(StringUtils.isBlank(ConfigConstants.DEFAULT_CATE_MAP.get(cateCode))){
                    returnMsg.setError(ErrorCodeConstants.ERR_0001);
                    LOGGER.error("queryBrandJxcByDate cateCode is error,cateCode=" + cateCode);
                    return setGsonView(returnMsg);
                }
                
                // 店长或者督导权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId()) ||ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    BiStoreJxcCateInfo resp = storeGuideBiService.queryBrandJxcByDate(storeManDto,date,cateCode);
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryBrandJxcByDate not SALE_GUIDE,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryBrandJxcByDate error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    @RequestMapping("/queryBrandJxcByMonth.do")
    public MyGsonView queryBrandJxcByMonth(Principal principal,String month,String cateCode) {
        ReturnMsg<BiStoreJxcCateInfo> returnMsg = new ReturnMsg<BiStoreJxcCateInfo>();
        if (StringUtils.isBlank(month) || StringUtils.isBlank(cateCode)) {
            LOGGER.warn("queryBrandJxcByDate input is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                //如果不是八大品类
                if(StringUtils.isBlank(ConfigConstants.DEFAULT_CATE_MAP.get(cateCode))){
                    returnMsg.setError(ErrorCodeConstants.ERR_0001);
                    LOGGER.error("queryBrandJxcByDate cateCode is error,cateCode=" + cateCode);
                    return setGsonView(returnMsg);
                }
                
                // 店长或者督导权限
                if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                        || ClerkConstants.DEPUTY_STORE_KEEPER.equals(storeManDto.getPositionId()) ||ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
                    BiStoreJxcCateInfo resp = storeGuideBiService.queryBrandJxcByMonth(storeManDto,month,cateCode);
                    returnMsg.setData(resp);
                } else {
                    returnMsg.setError(ErrorCodeConstants.ERR_0035);
                    LOGGER.error("queryBrandJxcByMonth not SALE_GUIDE,staffId=" + storeManDto);
                }
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryBrandJxcByMonth error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 日月维度查询单品详情<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cmmdtyCode 单品编码
     * @param date 日查询YYYY-MM-DD，月查询YYYY-MM
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCmmdtySaleDetail.do")
    public MyGsonView queryCmmdtySaleDetail(Principal principal, String cmmdtyCode, String date) {
        LOGGER.info("queryCmmdtySaleDetail. cmmdtyCode:{}, date:{}",cmmdtyCode, date);
        ReturnMsg<Object> returnMsg = new ReturnMsg<Object>();
        // 判断日期是否为空
        if (StringUtils.isBlank(cmmdtyCode) || StringUtils.isBlank(date)) {
            LOGGER.error("queryCmmdtySaleDetail. param is null");
            returnMsg.setError(ErrorCodeConstants.ERR_0001);
        } else {
            try {
                StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                returnMsg.setData(biStoreDateService.queryCmmdtySaleDetail(storeManDto, cmmdtyCode, date));
            } catch (Exception e) {
                returnMsg.setError(ErrorCodeConstants.ERR_0002);
                LOGGER.error("queryCmmdtySaleDetail error,staffId=" + principal.getName(), e);
            }
        }
        return setGsonView(returnMsg);
    }
    
    /**
     * 
     * 功能描述: 日月维度单品销售列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param cateCode 督导身份，品类为必填项；店长为非必填
     * @param brandCode
     * @param cmmdtyCode
     * @param date date 日查询YYYY-MM-DD，月查询YYYY-MM
     * @param sortType
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryStoreCmmdtySaleDetails.do")
    public MyGsonView queryStoreCmmdtySaleDetails(Principal principal, String cateCode, String brandCode,
            String cmmdtyCode, String date, String sortType, Integer pageNo, Integer pageSize) {
        LOGGER.info("queryStoreCmmdtySaleDetails. cateCode:{}, brandCode:{}, cmmdtyCode:{}, date:{}, sortType:{}",
                new Object[] { cateCode, brandCode, cmmdtyCode, date, sortType });
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        ReturnMsg<CmmdtySaleDetailsDto> retMsg = new ReturnMsg<CmmdtySaleDetailsDto>();
        try {
            retMsg = biStoreDateService.queryStoreCmmdtySaleDetails(storeManDto, cateCode, brandCode, cmmdtyCode, date,
                    sortType, pageNo, pageSize);
        } catch (Exception e) {
            retMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryCmmdtySaleDetail error,staffId=" + principal.getName(), e);
        }
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 查询topN品牌列表<br>
     * 〈功能详细描述〉生产环境品牌不到300，没有考虑大数据量情况
     *
     * @param principal
     * @param cateCode
     * @param date 日期格式YYYY-MM-DD、YYYY-MM
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryTopBrandList.do")
    public MyGsonView queryTopNBrandList(Principal principal, String cateCode, String date) {
        LOGGER.info("queryTopBrandList. cateCode:{}, date:{}", cateCode, date);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        ReturnMsg<List<TopCateDto>> retMsg = new ReturnMsg<List<TopCateDto>>();
        try {
            retMsg = biStoreDateService.queryTopNBrandList(storeManDto, cateCode, date);
        } catch (Exception e) {
            retMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryCmmdtySaleDetail error,staffId=" + principal.getName(), e);
        }
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 日月维度查询单品平均单价列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param brandCode
     * @param date
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCmmdtyAvgPrice.do")
    public MyGsonView queryCmmdtyAvgPrice(Principal principal, String brandCode, String date, Integer pageSize,
            Integer pageNo) {
        LOGGER.info("queryCmmdtyAvgPrice. brandCode:{}, date:{}", brandCode, date);
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        ReturnMsg<CmmdtyAvgPriceDto> retMsg = new ReturnMsg<CmmdtyAvgPriceDto>();
        try {
            retMsg = biStoreDateService.queryCmmdtyAvgPrice(storeManDto, brandCode, date, pageSize, pageNo);
        } catch (Exception e) {
            retMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("queryCmmdtyAvgPrice error,staffId=" + principal.getName(), e);
        }
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 功能灰度开关。1开、0关<br>
     * 〈功能详细描述〉
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryVersionSwitch.do")
    public MyGsonView queryVersionSwitch() {
        LOGGER.info("queryVersionSwitch. ");
        ReturnMsg<String> retMsg = new ReturnMsg<String>();
        String switchFlag = "0";
        try {
            switchFlag = SCMConfigUtil.getConfig(ConfigConstants.VERSION_FUNCTION_SWITCH);
        } catch (Exception e) {
            LOGGER.error("queryVersionSwitch failed.", e);
        }
        retMsg.setData(StringUtils.isBlank(switchFlag) ? "0" : switchFlag);
        return setGsonView(retMsg);
    }
}
